package prac;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class Tui {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1= sc.nextLine().split(" ");
        Deque<Integer> deque = new LinkedList<>();
        for(String s:s1 ){
            deque.offer(Integer.valueOf(s));
        }
        List<record> records=new ArrayList<>();
        AtomicInteger index=new AtomicInteger();
        record record=null;
        AtomicInteger  ele=new AtomicInteger(0);
        List<record> filterSum;
        while(!deque.isEmpty()){
            index.addAndGet(1);
            ele.set(deque.poll());
            filterSum=records.stream().filter(e->e.suit(ele.get())).collect(Collectors.toList());
            if(filterSum.isEmpty()){
                record=new record();
                record.index=index.get();
                record.add(ele.get());
                records.add(record);
            }else{
                deque.offer(2*ele.get());
                record=filterSum.get(0);
                index.set(filterSum.get(0).getIndex()-1);;
                records=records.stream().filter(e->e.getIndex()<=index.get()).map(e->{
                    e.remove(index.get());
                    return e;
                }).collect(Collectors.toList());
            }
        }
      List<record> recordSet=  records.stream().filter(e->e.index==1).collect(Collectors.toList());

        System.out.println(recordSet.get(0).ele);
    }
    public static class record{
        int index;
        Integer sum=new Integer(0);
        List<Integer> ele=new ArrayList<>();
        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public int getSum() {
            return sum;
        }

        public void setSum(int sum) {
            this.sum = sum;
        }
        public void add(int i){
            sum=sum+i;
            ele.add(i);
        }
        public boolean suit(int i){
            if(sum.equals(i)){
                return  true;
            }
            add(i);
            return false;
        }
        public void remove(int indexBefore){
            List<Integer> temp=new ArrayList<>();
           for(int i=index-1;i<indexBefore;i++){
               temp.add(ele.get(i));
           }
            ele=temp;
            sum=ele.stream() .mapToInt(Integer::intValue).sum();
        }

    }
}

